package cn.dengta.webapp.trade.dao;

import cn.dengta.common.web.Page;
import cn.dengta.webapp.base.dao.BaseDao;
import cn.dengta.webapp.trade.entity.UserLevel;
import cn.dengta.webapp.user.entity.userLevel.UserLevelRule;
import cn.dengta.webapp.user.entity.userLevel.UserLevelRule.UserLevelRuleType;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 用户等级 Mapper 接口
 *
 * @author lgy
 * @since 2022-11-28
 */
public interface UserLevelDao extends BaseDao<UserLevel> {

	@Select("SELECT log.* FROM dt_user_level log JOIN dt_user u ON log.id = u.id ${ew.customSqlSegment}")
	Page<UserLevel> findPage(Page<UserLevel> page, @Param("ew") QueryWrapper<UserLevel> wrapper);

	@Select("SELECT * FROM dt_user_level_rule WHERE rule_type = #{ruleType} AND end_time > NOW() AND STATUS >= 1 LIMIT 1 ")
	UserLevelRule getByRuleType(@Param("ruleType") UserLevelRuleType ruleType);

}
